home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / parser / TXDocument.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  11.1 KB  |  509 lines

  1. package com.ibm.xml.parser;
  2.  
  3. import java.io.IOException;
  4. import java.io.Writer;
  5. import java.security.MessageDigest;
  6. import java.security.NoSuchAlgorithmException;
  7. import java.util.Enumeration;
  8. import org.w3c.dom.Attr;
  9. import org.w3c.dom.CDATASection;
  10. import org.w3c.dom.Comment;
  11. import org.w3c.dom.DOMException;
  12. import org.w3c.dom.DOMImplementation;
  13. import org.w3c.dom.Document;
  14. import org.w3c.dom.DocumentFragment;
  15. import org.w3c.dom.DocumentType;
  16. import org.w3c.dom.Element;
  17. import org.w3c.dom.Entity;
  18. import org.w3c.dom.EntityReference;
  19. import org.w3c.dom.Node;
  20. import org.w3c.dom.NodeList;
  21. import org.w3c.dom.ProcessingInstruction;
  22. import org.w3c.dom.Text;
  23.  
  24. public class TXDocument extends Parent implements Document {
  25.    static final long serialVersionUID = -7547414605402949958L;
  26.    static transient TXDocument s_instance = null;
  27.    static transient DOMImplementation s_domImpl = null;
  28.    transient MessageDigest messageDigest;
  29.    String defDigestAlgorithm = "MD5";
  30.    TXElement rootElement;
  31.    DTD doctype;
  32.    String standalone;
  33.    String xmlVersion;
  34.    String xmlEncoding;
  35.    boolean isCheckDocument = false;
  36.    boolean checkValidity = false;
  37.    boolean isProcessNamespace = false;
  38.    boolean isCheckNodeLoop = true;
  39.    boolean isAddFixedAttributes = true;
  40.    public String expandedNameSeparator = ":";
  41.  
  42.    public Object clone() {
  43.       return this.cloneNode(true);
  44.    }
  45.  
  46.    public synchronized Node cloneNode(boolean var1) {
  47.       ((Child)this).checkFactory();
  48.  
  49.       TXDocument var2;
  50.       try {
  51.          var2 = (TXDocument)this.getClass().newInstance();
  52.       } catch (InstantiationException var4) {
  53.          throw new LibraryException("TXDocument#cloneNode(): " + var4);
  54.       } catch (IllegalAccessException var5) {
  55.          throw new LibraryException("TXDocument#cloneNode(): " + var5);
  56.       }
  57.  
  58.       ((Child)var2).setFactory(this.getFactory());
  59.       var2.defDigestAlgorithm = "MD5";
  60.       var2.standalone = this.standalone;
  61.       var2.xmlVersion = this.xmlVersion;
  62.       var2.xmlEncoding = this.xmlEncoding;
  63.       var2.isCheckDocument = this.isCheckDocument;
  64.       var2.checkValidity = this.checkValidity;
  65.       var2.isProcessNamespace = this.isProcessNamespace;
  66.       var2.isCheckNodeLoop = this.isCheckNodeLoop;
  67.       var2.isAddFixedAttributes = this.isAddFixedAttributes;
  68.       if (var1) {
  69.          var2.children.ensureCapacity(super.children.getLength());
  70.  
  71.          for(int var3 = 0; var3 < super.children.getLength(); ++var3) {
  72.             ((Parent)var2).appendChild(super.children.item(var3).cloneNode(true));
  73.          }
  74.       }
  75.  
  76.       var2.rootElement = (TXElement)var2.getDocumentElement();
  77.       var2.doctype = var2.getDTD();
  78.       return var2;
  79.    }
  80.  
  81.    public synchronized boolean equals(Node var1, boolean var2) {
  82.       if (!(var1 instanceof TXDocument)) {
  83.          return false;
  84.       } else {
  85.          TXDocument var3 = (TXDocument)var1;
  86.          if (var3.standalone == null && this.standalone == null || var3.standalone != null && var3.standalone.equals(this.standalone)) {
  87.             if (var3.xmlVersion == null && this.xmlVersion == null || var3.xmlVersion != null && var3.xmlVersion.equals(this.xmlVersion)) {
  88.                if (var3.xmlEncoding == null && this.xmlEncoding == null || var3.xmlEncoding != null && var3.xmlEncoding.equals(this.xmlEncoding)) {
  89.                   return !var2 || var3.children.equals(super.children, var2);
  90.                } else {
  91.                   return false;
  92.                }
  93.             } else {
  94.                return false;
  95.             }
  96.          } else {
  97.             return false;
  98.          }
  99.       }
  100.    }
  101.  
  102.    public short getNodeType() {
  103.       return 9;
  104.    }
  105.  
  106.    public String getNodeName() {
  107.       return "#document";
  108.    }
  109.  
  110.    public Element getDocumentElement() {
  111.       return this.rootElement;
  112.    }
  113.  
  114.    void setDocumentElement(Element var1) {
  115.       this.rootElement = (TXElement)var1;
  116.    }
  117.  
  118.    public String getRootName() {
  119.       return this.rootElement == null ? null : this.rootElement.getTagName();
  120.    }
  121.  
  122.    public NodeList getElementsByTagName(String var1) {
  123.       return (NodeList)(this.rootElement != null ? this.rootElement.getElementsByTagName(var1) : TXNodeList.emptyNodeList);
  124.    }
  125.  
  126.    public DocumentType getDoctype() {
  127.       return this.doctype;
  128.    }
  129.  
  130.    public DTD getDTD() {
  131.       return this.doctype;
  132.    }
  133.  
  134.    public boolean isCheckValidity() {
  135.       return this.checkValidity;
  136.    }
  137.  
  138.    protected void resetCheckValidity() {
  139.       this.checkValidity = false;
  140.       if (this.doctype != null) {
  141.          Enumeration var1 = this.doctype.getElementDeclarations();
  142.          if (var1.hasMoreElements()) {
  143.             this.checkValidity = true;
  144.          }
  145.       }
  146.  
  147.    }
  148.  
  149.    public String getStandalone() {
  150.       return this.standalone;
  151.    }
  152.  
  153.    public boolean isStandalone() {
  154.       return this.standalone == null ? false : "yes".equals(this.standalone);
  155.    }
  156.  
  157.    public void setStandalone(String var1) {
  158.       this.standalone = var1;
  159.       if (this.xmlVersion == null) {
  160.          this.xmlVersion = "1.0";
  161.       }
  162.  
  163.    }
  164.  
  165.    public String getVersion() {
  166.       return this.xmlVersion;
  167.    }
  168.  
  169.    public void setVersion(String var1) {
  170.       this.xmlVersion = var1;
  171.    }
  172.  
  173.    public String getEncoding() {
  174.       return this.xmlEncoding;
  175.    }
  176.  
  177.    public void setEncoding(String var1) {
  178.       this.xmlEncoding = var1;
  179.       if (this.xmlVersion == null) {
  180.          this.xmlVersion = "1.0";
  181.       }
  182.  
  183.    }
  184.  
  185.    public void setProcessNamespace(boolean var1) {
  186.       this.isProcessNamespace = var1;
  187.    }
  188.  
  189.    public boolean isProcessNamespace() {
  190.       return this.isProcessNamespace;
  191.    }
  192.  
  193.    protected void realInsert(Node var1, int var2) throws LibraryException {
  194.       super.realInsert(var1, var2);
  195.       if (var1 instanceof DTD) {
  196.          if (this.doctype != null) {
  197.             this.removeChild(this.doctype);
  198.          }
  199.  
  200.          this.doctype = (DTD)var1;
  201.       } else {
  202.          if (var1 instanceof TXElement) {
  203.             if (this.rootElement != null) {
  204.                throw new LibraryException("com.ibm.xml.parser.TXDocument#insert(): Document root Element was set twice.");
  205.             }
  206.  
  207.             this.setDocumentElement((Element)var1);
  208.          }
  209.  
  210.       }
  211.    }
  212.  
  213.    public Node replaceChild(Node var1, Node var2) throws DOMException {
  214.       if (var1.getNodeType() == 1 && this.getDocumentElement() != null && var2.getNodeType() != 1) {
  215.          throw new TXDOMException((short)3, "Root element already exists.");
  216.       } else {
  217.          super.replaceChild(var1, var2);
  218.          if (var1.getNodeType() != 1 && var2.getNodeType() == 1) {
  219.             this.setDocumentElement((Element)null);
  220.          }
  221.  
  222.          if (var1.getNodeType() == 1) {
  223.             this.setDocumentElement((Element)var1);
  224.          }
  225.  
  226.          return var2;
  227.       }
  228.    }
  229.  
  230.    public Node removeChild(Node var1) throws DOMException {
  231.       super.removeChild(var1);
  232.       if (var1 == this.getDocumentElement()) {
  233.          this.setDocumentElement((Element)null);
  234.       } else if (var1 == this.getDoctype()) {
  235.          this.doctype = null;
  236.       }
  237.  
  238.       return var1;
  239.    }
  240.  
  241.    public void printWithFormat(Writer var1) throws IOException, LibraryException {
  242.       this.printWithFormat(var1, (String)null, 2);
  243.    }
  244.  
  245.    public void printWithFormat(Writer var1, String var2) throws IOException, LibraryException {
  246.       this.printWithFormat(var1, var2, 2);
  247.    }
  248.  
  249.    public void printWithFormat(Writer var1, String var2, int var3) throws IOException, LibraryException {
  250.       try {
  251.          FormatPrintVisitor var4 = new FormatPrintVisitor(var1, var2, var3);
  252.          (new NonRecursivePreorderTreeTraversal(var4)).traverse(this);
  253.       } catch (IOException var5) {
  254.          throw var5;
  255.       } catch (Exception var6) {
  256.          throw new LibraryException("com.ibm.xml.parser.TXDocument#printWithFormat(): Unexpected Exception: " + ((Throwable)var6).toString());
  257.       }
  258.    }
  259.  
  260.    public void setPrintInternalDTD(boolean var1) {
  261.       if (this.doctype != null) {
  262.          this.doctype.setPrintInternalDTD(var1);
  263.       }
  264.  
  265.    }
  266.  
  267.    public String getText() {
  268.       return this.rootElement != null ? this.rootElement.getText() : "";
  269.    }
  270.  
  271.    public DOMImplementation getImplementation() {
  272.       if (s_domImpl == null) {
  273.          s_domImpl = new 1();
  274.       }
  275.  
  276.       return s_domImpl;
  277.    }
  278.  
  279.    public void acceptPre(Visitor var1) throws Exception {
  280.       var1.visitDocumentPre(this);
  281.    }
  282.  
  283.    public void acceptPost(Visitor var1) throws Exception {
  284.       var1.visitDocumentPost(this);
  285.    }
  286.  
  287.    public Document getOwnerDocument() {
  288.       return null;
  289.    }
  290.  
  291.    public TXDocument getFactory() {
  292.       return this;
  293.    }
  294.  
  295.    public static TXDocument getInstance() {
  296.       if (s_instance == null) {
  297.          s_instance = new TXDocument();
  298.       }
  299.  
  300.       return s_instance;
  301.    }
  302.  
  303.    public Element createElement(String var1) throws DOMException {
  304.       if (!Util.checkName(var1)) {
  305.          throw new TXDOMException((short)5, "Invalid name: " + var1);
  306.       } else {
  307.          TXElement var2 = new TXElement(var1);
  308.          ((Child)var2).setFactory(this);
  309.          return var2;
  310.       }
  311.    }
  312.  
  313.    public Attr createAttribute(String var1) throws DOMException {
  314.       if (!Util.checkName(var1)) {
  315.          throw new TXDOMException((short)5, "Invalid name: " + var1);
  316.       } else {
  317.          TXAttribute var2 = new TXAttribute(var1, (String)null);
  318.          ((Child)var2).setFactory(this);
  319.          return var2;
  320.       }
  321.    }
  322.  
  323.    TXText createAttributeValue(String var1) {
  324.       return this.createTextNode(var1, false);
  325.    }
  326.  
  327.    public Text createTextNode(String var1) {
  328.       return this.createTextNode(var1, false);
  329.    }
  330.  
  331.    public TXText createTextNode(String var1, boolean var2) {
  332.       TXText var3 = new TXText(var1);
  333.       ((Child)var3).setFactory(this);
  334.       var3.setIsIgnorableWhitespace(var2);
  335.       return var3;
  336.    }
  337.  
  338.    public TXText createTextNode(char[] var1, int var2, int var3, boolean var4) {
  339.       TXText var5 = new TXText(new String(var1, var2, var3));
  340.       ((Child)var5).setFactory(this);
  341.       var5.setIsIgnorableWhitespace(var4);
  342.       return var5;
  343.    }
  344.  
  345.    public CDATASection createCDATASection(String var1) throws DOMException {
  346.       TXCDATASection var2 = new TXCDATASection(var1);
  347.       ((Child)var2).setFactory(this);
  348.       return var2;
  349.    }
  350.  
  351.    public Comment createComment(String var1) {
  352.       TXComment var2 = new TXComment(var1);
  353.       ((Child)var2).setFactory(this);
  354.       return var2;
  355.    }
  356.  
  357.    public ProcessingInstruction createProcessingInstruction(String var1, String var2) throws DOMException {
  358.       if (!Util.checkName(var1)) {
  359.          throw new TXDOMException((short)5, "Invalid PI target name: " + var1);
  360.       } else {
  361.          TXPI var3 = new TXPI(var1, var2);
  362.          ((Child)var3).setFactory(this);
  363.          return var3;
  364.       }
  365.    }
  366.  
  367.    public StylesheetPI createStylesheetPI(String var1, String var2, String var3, String var4, String var5) {
  368.       StylesheetPI var6 = new StylesheetPI(var1, var2, var3, var4, var5);
  369.       ((Child)var6).setFactory(this);
  370.       return var6;
  371.    }
  372.  
  373.    public DTD createDTD() {
  374.       DTD var1 = new DTD();
  375.       ((Child)var1).setFactory(this);
  376.       return var1;
  377.    }
  378.  
  379.    public DTD createDTD(String var1, ExternalID var2) {
  380.       DTD var3 = new DTD(var1, var2);
  381.       ((Child)var3).setFactory(this);
  382.       return var3;
  383.    }
  384.  
  385.    public ElementDecl createElementDecl(String var1, ContentModel var2) {
  386.       ElementDecl var3 = new ElementDecl(var1, var2);
  387.       ((Child)var3).setFactory(this);
  388.       return var3;
  389.    }
  390.  
  391.    public ContentModel createContentModel(int var1) {
  392.       ContentModel var2 = new ContentModel(var1);
  393.       var2.setFactory(this);
  394.       return var2;
  395.    }
  396.  
  397.    public ContentModel createContentModel(CMNode var1) {
  398.       ContentModel var2 = new ContentModel(var1);
  399.       var2.setFactory(this);
  400.       return var2;
  401.    }
  402.  
  403.    public Attlist createAttlist(String var1) {
  404.       Attlist var2 = new Attlist(var1);
  405.       ((Child)var2).setFactory(this);
  406.       return var2;
  407.    }
  408.  
  409.    public AttDef createAttDef(String var1) {
  410.       AttDef var2 = new AttDef(var1);
  411.       ((Child)var2).setFactory(this);
  412.       return var2;
  413.    }
  414.  
  415.    public EntityDecl createEntityDecl(String var1, String var2, boolean var3) {
  416.       EntityDecl var4 = new EntityDecl(var1, var2, var3);
  417.       ((Child)var4).setFactory(this);
  418.       return var4;
  419.    }
  420.  
  421.    public EntityDecl createEntityDecl(String var1, ExternalID var2, boolean var3, String var4) {
  422.       EntityDecl var5 = new EntityDecl(var1, var2, var3, var4);
  423.       ((Child)var5).setFactory(this);
  424.       return var5;
  425.    }
  426.  
  427.    public TXNotation createNotation(String var1, ExternalID var2) {
  428.       TXNotation var3 = new TXNotation(var1, var2);
  429.       ((Child)var3).setFactory(this);
  430.       return var3;
  431.    }
  432.  
  433.    public EntityReference createEntityReference(String var1) throws DOMException {
  434.       if (!Util.checkName(var1)) {
  435.          throw new TXDOMException((short)5, "Invalid entity name: " + var1);
  436.       } else {
  437.          GeneralReference var2 = new GeneralReference(var1);
  438.          ((Child)var2).setFactory(this);
  439.          return var2;
  440.       }
  441.    }
  442.  
  443.    public DocumentFragment createDocumentFragment() {
  444.       TXDocumentFragment var1 = new TXDocumentFragment();
  445.       ((Child)var1).setFactory(this);
  446.       return var1;
  447.    }
  448.  
  449.    public Entity createEntity() {
  450.       return null;
  451.    }
  452.  
  453.    public MessageDigest createMessageDigest() throws NoSuchAlgorithmException {
  454.       if (this.messageDigest == null) {
  455.          this.messageDigest = MessageDigest.getInstance(this.defDigestAlgorithm);
  456.       } else {
  457.          this.messageDigest.reset();
  458.       }
  459.  
  460.       return this.messageDigest;
  461.    }
  462.  
  463.    public void setDigestAlgorithm(String var1) {
  464.       if (!this.defDigestAlgorithm.equals(var1)) {
  465.          this.defDigestAlgorithm = var1;
  466.          this.messageDigest = null;
  467.       }
  468.  
  469.    }
  470.  
  471.    protected void checkChildType(Node var1) throws DOMException {
  472.       switch (var1.getNodeType()) {
  473.          case 1:
  474.          case 3:
  475.          case 7:
  476.          case 8:
  477.          case 10:
  478.          case 23:
  479.             return;
  480.          default:
  481.             throw new TXDOMException((short)3, "Specified node type (" + var1.getNodeType() + ") can't be a child of Document.");
  482.       }
  483.    }
  484.  
  485.    public boolean isCheckOwnerDocument() {
  486.       return this.isCheckDocument;
  487.    }
  488.  
  489.    public void setCheckOwnerDocument(boolean var1) {
  490.       this.isCheckDocument = var1;
  491.    }
  492.  
  493.    public boolean isCheckNodeLoop() {
  494.       return this.isCheckNodeLoop;
  495.    }
  496.  
  497.    public void setCheckNodeLoop(boolean var1) {
  498.       this.isCheckNodeLoop = var1;
  499.    }
  500.  
  501.    public boolean isAddFixedAttributes() {
  502.       return this.isAddFixedAttributes;
  503.    }
  504.  
  505.    public void setAddFixedAttributes(boolean var1) {
  506.       this.isAddFixedAttributes = var1;
  507.    }
  508. }
  509.